<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>数据导入（卡厂批量）</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
 <script type="text/javascript" src="${pageContext.request.contextPath }/js/ajaxfileupload.js"></script>  
<style type="text/css">
		html,body {
		    margin: 0;
		    padding: 0;
		    border: 0;
		    width: 100%;
		    height: 100%;
		    overflow: hidden;
		}
	</style>
</head>
<body>
	  <fieldset style="border:solid 1px #aaa;padding:3px;">
	  <div style="width:100%;height:33px;">
	  <form id="form1"  enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/AZ20.do?method=exkcdate">
	    <table style="border:solid 1px #aaa;width:100%;">
	      <tr>
	        <td style="width:6%;text-align:right;white-space:nowrap;">制卡批次:</td>
	        <td style="width:25%;"><input name="aaz001" class="mini-textbox" emptyText="请输入制卡批次" required="true" maxlength="10" style="width:60%;"/></td>
	        <td style="width:6%;text-align:right;white-space:nowrap;">银行：</td>
	        <td style="width:25%;"><input name="aae008" class="mini-combobox" required="true" style="width:60%;" textField="aaa103" valueField="aaa102"
	                                      emptyText="请选择银行" 
	                                      url="${pageContext.request.contextPath }/kid.do?method=getyinhang&sj=bank"/><input name="eventid" id="eventid" class="mini-hidden" style="width:60%" />
	        </td>
	        <td style="width:6%;text-align:right;white-space:nowrap;">回盘文件：</td>
	        <td style="width:25%;"><input type="file" name="file" id="file" style="width:100%;" />
	        </td>	       	
	      </tr>
	    </table>
	    </form>
	  </div>
  </fieldset>
	<div>
	  <div id="datagrid1" class="mini-datagrid" style="width:100%;height:390px;" allowResize="true" showReloadButton="false" showPageInfo="false"
	       url="AZ20.do?method=gettemp" idField="id" multiSelect="true" frozenStartColumn="0" frozenEndColumn="2">
	    <div property="columns">
	    <div type="indexcolumn" ></div>		
	      <div field="aac003" width="100" headerAlign="center" >姓名</div>
	      <div field="aac004" width="80" headerAlign="center"  >性别</div>
	      <div field="aac005" width="80" headerAlign="center" >民族</div>
	      <div field="aac001" width="150" headerAlign="center" >社会保障卡号</div>
	      <div field="aac002" width="150" headerAlign="center" >证件号</div>
	      <div field="aaz632" width="100" headerAlign="center" >盒号</div>
	      <div field="aaz501" width="150" headerAlign="center" >卡识别号</div>
	      <div field="caz002" width="150" headerAlign="center" >通卡卡面号</div>
	      <div field="caz003" width="150" headerAlign="center" >通卡卡内号</div>
	      <div field="aae008" width="120" headerAlign="center" >银行</div>
	      <div field="aae009" width="150" headerAlign="center" >银行卡号</div>
	      <div field="execmsg" width="150" headerAlign="center" >错误信息</div>
	    </div>
	  </div>
	</div>
	<div style="padding-bottom:5px;">
	    <table style="border:solid 1px #aaa;width:100%;">
	      <tr>
			<td style="width:10%;text-align: right;white-space:nowrap;">导出人数:</td>
	        <td style="width:15%;"><input name="exprs" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true" /></td>
			<td style="width:10%;text-align: right;white-space:nowrap;">已导入人数:</td>
	        <td style="width:15%;"><input  name="imprs1" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true" /></td>
	        <td style="width:10%;text-align: right;white-space:nowrap;">导入人数:</td>
	        <td style="width:15%;"><input  name="imprs2" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true" /></td>
	        <td style="width:10%;text-align: right;white-space:nowrap;">错误人数:</td>
	        <td style="width:15%;"><input  name="errrs" class="mini-textbox" inputStyle="background:rgb(241,241,243)" allowInput="false" readonly="true"/></td>
	      </tr>
	    </table>
	  </div>
	  <div>
	  <table>
	  <tr>
	  <td style="width:15%;text-align: center; white-space:nowrap;">
	  <a class="mini-button" id="check" onclick="interExcel"  iconCls="icon-ok"  >导入</a>
	  <a class="mini-button" id="exporter" enabled="false"  onclick="exportExcel" iconCls="icon-upload" >错误数据文件</a>
	  <a class="mini-button" id="onoks" enabled="false" onclick="onOk" iconCls="icon-ok" >确认</a>
	  <a class="mini-button"  onclick="onReset" iconCls="icon-remove" >重置</a>
	  </td>
	  </tr>
	  </table>
	  </div>
	<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1"); 
var form = new mini.Form("form1");        
        function check() {            	
			var o = form.getData();				
			form.validate();
			if (form.isValid() == false)
			return;
			var eventid = mini.getbyName("eventid").getValue().trim();  
			if(eventid.length>20) {
              eventid=eventid.substring(eventid.length-22,eventid.length-6); 
              mini.getbyName("eventid").setValue(eventid);             
              }
               if(form.isValid()==true){
      	  		mini.mask({el: document.body,cls: 'mini-mask-loading',html: '导入中...'});    
			var json = mini.encode([o]);
			$.ajax({
				url : "/sbk/AZ20.do?method=checkkcdata",
				type : 'post',
				data : {
					data : json
				},
				cache : false,
				success : function(text) {	
				 var o = mini.decode(text);
				 var result = o.result;				
				 if(result=="0")
				 {
				 mini.unmask();
				 mini.getbyName("exprs").setValue(o.exprs);
				 mini.getbyName("imprs1").setValue(o.imprs1);
				 mini.getbyName("imprs2").setValue(o.imprs2);
				 mini.getbyName("errrs").setValue(o.errrs);
				 mini.get("onoks").setEnabled(true);
				 mini.get("exporter").setEnabled(true);
				 search();
				 }
				else
				{
				  mini.alert(result);
				  mini.unmask();
				}
				  		  															
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.alert(jqXHR.responseText);	
					mini.unmask();				
				}
			});	
              }                                            
        }

  function interExcel()
        {                  			
			form.validate();
			if (form.isValid() == false)
			{
			   mini.alert("请输入制卡批次和银行");
			    return;
			} 
			var value = $("#file").attr("value");                   
            if(value == "" || value == null)
            {               
               mini.alert("请上传文件");
               return;            
            }else {		    
            var arrId=new Array(); 
            arrId[0] ="file" ;     	
            $.ajaxFileUpload({
	            url:"${pageContext.request.contextPath }/file.do?method=dofile",
	            type : 'post',
	            secureuri : false,
	            fileElementId : arrId,
	            dataType : 'text',
	            success: function (text) {   
	            if("" == text || null == text || "null" == text)
	            {
	              mini.alert("上传失败");
	            }
	            else
	            {
	               mini.getbyName("eventid").setValue(text);
	               mini.get("check").setEnabled(false); 
	               labelModel(); 
	               labelModel2(); 
	               check();             
	            }
	                
	           }          
            });
               }	                
        }
        
        function onOk()
        {
        
        SaveData();
        }
        
        function search()
        {          
           var id = mini.getbyName("eventid").getValue().trim();                   
            if(id!="" || id!=null)
            {
             grid.load({id: id});
            }
            
        }
        
         function SaveData() {
			var o = form.getData();				
			form.validate();
			if (form.isValid() == false)
			return;
			 if(form.isValid()==true){
      	  		mini.mask({el: document.body,cls: 'mini-mask-loading',html: '保存中...'});    
			var json = mini.encode([o]);		
			$.ajax({
				url : "/sbk/AZ20.do?method=savekcdata",
				type : 'post',
				data : {
					datas : json
				},
				cache : false,
				success : function(text) {	
				mini.unmask();
				      if("0"== text)
				    {
				     mini.alert("登记成功");
				     mini.get("onoks").setEnabled(false);
				    }
				    else
				    {
				      mini.alert("登记失败:"+text);
				    }						   							
				},
				error : function(jqXHR, textStatus, errorThrown) {
					mini.alert(jqXHR.responseText);					
				}
			});
          }
		}	
		
		function exportExcel()
		{
		    var eventid = mini.getbyName("eventid").getValue().trim();   
		     if(eventid!=""){
		    var form1 = document.getElementById("form1");	
			form1.submit();
		     } 
		     else
		    {
		       mini.alert("请导入文件");
		    }
		   
		}
		
		function labelModel() {
            var fields = form.getFields();                          
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观           
        }
        
        function labelModel2() {
            var fields = form.getFields();                          
                var c = fields[1];
                if (c.setReadOnly) c.setReadOnly(true);     //只读
                if (c.setIsValid) c.setIsValid(true);      //去除错误提示
                if (c.addCls) c.addCls("asLabel");          //增加asLabel外观           
        }
        
         function inputModel2() {
            var fields = form.getFields();           
                var c = fields[0];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");          
            mini.repaint(document.body);
        }
        
         function inputModel1() {
            var fields = form.getFields();           
                var c = fields[1];
                if (c.setReadOnly) c.setReadOnly(false);
                if (c.removeCls) c.removeCls("asLabel");          
            mini.repaint(document.body);
        }
	    function onReset(e) {
	        mini.get("onoks").setEnabled(false);
	        mini.get("check").setEnabled(true); 
			mini.get("exporter").setEnabled(false);
			var file = document.getElementById("file");
            file.style.display="block";
            file.outerHTML=file.outerHTML.replace(/(value=\").+\"/i,"$1\""); 
			inputModel2();
			inputModel1();
			form.clear();
			grid.load();	    	
	    	mini.getbyName("exprs").setValue("");
		    mini.getbyName("imprs1").setValue("");
	        mini.getbyName("imprs2").setValue("");
		    mini.getbyName("errrs").setValue("");
		}
	</script>
</body>
</html>
